<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="商品名称">
              <a-input placeholder="请输入商品名称" v-model="queryParam.productName"></a-input>
            </a-form-item>
          </a-col>
           <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="商品型号">
              <a-input placeholder="请输入商品型号" v-model="queryParam.productModel"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="商品类型">
              <a-input placeholder="请输入商品类型" v-model="queryParam.productType"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- 查看信息的弹框 -->
      <div>
        <a-button type="primary" style="float: right;" @click="showModal">
          查看信息
        </a-button>
        <a-modal v-model="visible" title="查看信息" @ok="handleOk">
          <p>总金额(元):&nbsp;&nbsp;&nbsp;{{money}}</p>
          <p>剩余数量(个):&nbsp;&nbsp;&nbsp;{{num}}</p>
          
        </a-modal>
      </div>
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('电感')">导出</a-button>
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>-->
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

<!-- pdf文件 -->
        <span slot="action" slot-scope="text, record">
          <!-- 查看-->
          <a-icon @click="dataBook(record.id)" type="folder-open"></a-icon>
          <a-divider type="vertical" />
           <a-dropdown>
            <a class="ant-dropdown-link">数据手册<a-icon type="down" /></a>
            <a-menu slot="overlay">
               <!-- 文件上传 -->
              <a-menu-item>
               <a @click="dataInsert()">上传</a>
              <a-modal
                :visible="textShow"
                :confirmLoading="confirmLoading"
                @ok="fileOk(record.id)"
                @cancel="handleCancel"
                cancelText="关闭">
                <j-upload v-model="fileList" text="上传"></j-upload>
              </a-modal>
              </a-menu-item>
              <!-- 文件下载 -->
<!--              <a-menu-item>
                <a @click="downloadFiles(record.id)" type='primary' size='small' icon='download'>下载</a>
              </a-menu-item>-->
              <!-- 文件删除 -->
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="dataDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
          <a-divider type="vertical" />


          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <!--  选择移出   -->
              <a-menu-item>
                <a @click="showSelect">移至</a>
                <a-modal v-model="moreStore" title="" width='400px' @ok="Nice(record.id)">
                   选择移入位置：<select v-model="selected" name="fruit">
                      <option disabled value="">请选择</option>
                      <option :value="index" v-for="(coupon,index) in couponList">{{coupon}}</option>
                    </select>
                </a-modal>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <axhk-dg-inductance-modal ref="modalForm" @ok="modalFormOk"></axhk-dg-inductance-modal>
  </a-card>
</template>

<script>
  import { httpAction, getAction } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import AxhkDgInductanceModal from './modules/AxhkDgInductanceModal'
  import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'
  import JUpload from '@/components/jeecg/JUpload'
  
  export default {
    name: 'AxhkDgInductanceList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      AxhkDgInductanceModal,
      JSuperQuery,
      JUpload,
    },
    inject:['reload'],
    data () {
      return {
        description: '电感管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'商品名称',
            align:"center",
            dataIndex: 'productName'
          },
          {
            title:'商品型号',
            align:"center",
            dataIndex: 'productModel'
          },
          {
            title:'商品类型',
            align:"center",
            dataIndex: 'productType'
          },
          {
            title:'商品品牌',
            align:"center",
            dataIndex: 'productBrand'
          },
          {
            title:'购买单价(元)',
            align:"center",
            dataIndex: 'pricePerUnit'
          },
          {
            title:'购买数量(个)',
            align:"center",
            dataIndex: 'pricePerNum'
          },
          {
            title:'现有数量(个)',
            align:"center",
            dataIndex: 'nowNumber'
          },
          {
            title:'剩余数量(个)',
            align:"center",
            dataIndex: 'residueNumber'
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/fly/axhkDgInductance/list",
          delete: "/fly/axhkDgInductance/delete",
          deleteBatch: "/fly/axhkDgInductance/deleteBatch",
          exportXlsUrl: "/fly/axhkDgInductance/exportXls",
          importExcelUrl: "fly/axhkDgInductance/importExcel",
          look: "/fly/axhkDgInductance/getByAxhkDgInductance",
          date:"/fly/axhkDgInductance/getByDgInductanceDate",
          menu:"/fly/axhkTMenu/getByTMenus",
          path:"/fly/axhkDgInductance/getByUpdateDgInductancePath",
          deletePath:"/fly/axhkDgInductance/getByUpdatePath",
          lookPath:"/jeecg-boot/fly/axhkDgInductance/getByLookFile",
          lookss:"/fly/axhkDgInductance/LookFile",
          //downloadFile:"/jeecg-boot/fly/axhkDgInductance/downloadFile",
        },
        dictOptions:{},
        superFieldList:[],
        visible: false,
        money:'',
        num: '',
        moreStore: false,
        textShow:false,
        selected: '',
        menuId:'1381779754116767745',
        /*选项列表*/
        couponList:[],
        fileList:[],
        name:'电感',
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      showModal() {
        this.visible = true;
         getAction(this.url.look).then((res)=>{
            if(res.success){
              this.money=res.result.retals
              this.num=res.result.number
              // alert(this.money)
              // alert(this.num)
            } 
          }); 
      },
      showSelect() {
        this.moreStore = true;
        getAction(this.url.menu,{id:this.menuId}).then((res)=>{
          if(res != null){
            this.couponList = res.result;
          }
        });
      },
      dataInsert(){
        this.textShow = true;
      },
      handleOk(e) {
        console.log(e);
        this.visible = false;
      },
      /*点击确定*/
      Nice(e){
        if(this.selected != null){
          getAction(this.url.date,{id:e,num:this.selected}).then((res)=>{
            if(res.success){
              this.moreStore = false;
              this.reload();
              this.$message.success(res.message);
            }
          });
        }else {
          alert("请选择菜单!");
        }
      },

      dataBook(a){
        /*点击查看pdf文件*/
        getAction(this.url.lookss,{id:a}).then((res)=>{
          if(res.success){
            var b = res.result;
            if(b == 1){
              const urls = this.url.lookPath+"?id="+a;
              window.open('/pdf/web/viewer.html?file=' + encodeURIComponent(urls));
            }else{
              alert("未上传可用文件！")
            }
          }
        })
      },
      /*文件上传*/
      fileOk(e){
        //点击确定
        if(this.fileList.length > 0){
          getAction(this.url.path,{id:e,names:this.name}).then((res)=>{
            if(res.success){
              var a = res.result;
              if(a==1){
                this.reload();
                return;
              }{
                this.reload();
                alert("已经有文件请先删除文件再上传！")
              }
            }
          })
          this.textShow = false;
          formData.file = this.fileList;
          this.reload();
        }else{
          this.textShow = false;
          alert("请正确选择PDF文件上传!");
        }
      },
      handleCancel(){
        //关闭 取消
        this.textShow = false;
      },

      dataDelete(e){
        //删除上传文件 deletePath
        getAction(this.url.deletePath,{id:e}).then((res)=> {
          if (res.success) {
            var a = res.result;
            switch (a){
              case 0:
                alert("删除文件不成功!");
                break;
              case 1:
                alert("删除文件成功!");
                break;
              case 2:
                alert("未有文件可删!");
            }
          }
        })
      },
     /* downloadFiles(e){ //pdf文件下载
        getAction(this.url.lookss,{id:e}).then((res)=>{
          if(res.success){
            var b = res.result;
            if(b == 1){
              const urls = this.url.downloadFile+"?id="+e;
              window.location.href = urls;
            }else{
              alert("没有文件下载！")
            }
          }
        })
      },*/

      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'productName',text:'商品名称',dictCode:''})
        fieldList.push({type:'string',value:'productModel',text:'商品型号',dictCode:''})
        fieldList.push({type:'string',value:'productType',text:'商品类型',dictCode:''})
        fieldList.push({type:'string',value:'productBrand',text:'商品品牌',dictCode:''})
        fieldList.push({type:'double',value:'pricePerUnit',text:'购买单价',dictCode:''})
        fieldList.push({type:'int',value:'pricePerNum',text:'购买数量',dictCode:''})
        fieldList.push({type:'string',value:'nowNumber',text:'现有数量',dictCode:''})
        fieldList.push({type:'string',value:'residueNumber',text:'剩余数量',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>